\section{handler::multicaster Class Reference}
\label{classhandler_1_1multicaster}\index{handler::multicaster@{handler::multicaster}}
This class implements the multicaster, at which handlers can register themselves.  


{\tt \#include $<$multicaster.h$>$}

Inheritance diagram for handler::multicaster::\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[height=2cm]{classhandler_1_1multicaster}
\end{center}
\end{figure}
\subsection*{Public Types}
\begin{CompactItemize}
\item 
typedef boost::shared\_\-ptr$<$ network::event\_\-handler $>$ \bf{event\_\-ptr}\label{classhandler_1_1multicaster_6589830399006e17f36eaf08e5083c50}

\end{CompactItemize}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
\bf{multicaster} (boost::shared\_\-ptr$<$ \bf{network::message\_\-queue} $>$ q, int num\_\-threads=5)
\begin{CompactList}\small\item\em multicaster creates the multicaster. Don't use this constuctor directly, call create-instead. \item\end{CompactList}\item 
virtual \bf{$\sim$multicaster} ()\label{classhandler_1_1multicaster_80bbe803f2be8b01015c98a3961f84dd}

\item 
void \bf{dispatch} (boost::shared\_\-ptr$<$ \bf{network::message} $>$ msg)
\begin{CompactList}\small\item\em dispatch dispatches a received message. This method is called by worker\_\-thread threads. \item\end{CompactList}\item 
void \bf{add\_\-handler} (\bf{network::event\_\-type} t, boost::shared\_\-ptr$<$ \bf{network::i\_\-socket} $>$ sock, boost::shared\_\-ptr$<$ \bf{handler::event\_\-handler} $>$ h)
\begin{CompactList}\small\item\em add\_\-handler adds a new handler to the multicaster. \item\end{CompactList}\item 
void \bf{remove\_\-handler} (\bf{network::event\_\-type} t, boost::shared\_\-ptr$<$ \bf{network::i\_\-socket} $>$ sock, boost::shared\_\-ptr$<$ \bf{handler::event\_\-handler} $>$ h)\label{classhandler_1_1multicaster_cbdc306ebf8906a25b478a927432b6ba}

\begin{CompactList}\small\item\em remove\_\-handler removes a handler from the multicaster \item\end{CompactList}\item 
virtual void \bf{notify} (const \bf{network::notifier} $\ast$n)
\begin{CompactList}\small\item\em notify is called by handler, if they want to delete themselves, if e.g. a connection was closed. \item\end{CompactList}\end{CompactItemize}
\subsection*{Static Public Member Functions}
\begin{CompactItemize}
\item 
static boost::shared\_\-ptr$<$ \bf{handler::multicaster} $>$ \bf{create} (boost::shared\_\-ptr$<$ \bf{network::message\_\-queue} $>$ q, int num\_\-threads=5)
\begin{CompactList}\small\item\em create creates the multicaster \item\end{CompactList}\end{CompactItemize}
\subsection*{Classes}
\begin{CompactItemize}
\item 
struct \bf{event\_\-storage}
\end{CompactItemize}


\subsection{Detailed Description}
This class implements the multicaster, at which handlers can register themselves. 



Definition at line 58 of file multicaster.h.

\subsection{Constructor \& Destructor Documentation}
\index{handler::multicaster@{handler::multicaster}!multicaster@{multicaster}}
\index{multicaster@{multicaster}!handler::multicaster@{handler::multicaster}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}handler::multicaster::multicaster (boost::shared\_\-ptr$<$ \bf{network::message\_\-queue} $>$ {\em q}, int {\em num\_\-threads} = {\tt 5})}\label{classhandler_1_1multicaster_2a0ae8d6ccd8bd7f2d3bec7e740ecf69}


multicaster creates the multicaster. Don't use this constuctor directly, call create-instead. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em q}]is the message\_\-queue which should be used. \item[{\em num\_\-threads}]is the number of worker threads. default: 5 \end{description}
\end{Desc}


Definition at line 3 of file multicaster.cpp.

\begin{Code}\begin{verbatim}5 : _message_q(q)
6 {
7         boost::shared_ptr<handler::event_worker> worker;
8         for(int i = 0; i < num_threads; ++i) {
9                 worker.reset(new handler::event_worker(_this, _message_q));
10                 worker->start_thread();
11                 _workers.push_back(worker);
12         }
13 }
\end{verbatim}\end{Code}




\subsection{Member Function Documentation}
\index{handler::multicaster@{handler::multicaster}!add_handler@{add\_\-handler}}
\index{add_handler@{add\_\-handler}!handler::multicaster@{handler::multicaster}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void handler::multicaster::add\_\-handler (\bf{network::event\_\-type} {\em t}, boost::shared\_\-ptr$<$ \bf{network::i\_\-socket} $>$ {\em sock}, boost::shared\_\-ptr$<$ \bf{handler::event\_\-handler} $>$ {\em h})}\label{classhandler_1_1multicaster_fa8ce328e35bb6a337ecfffb76770cf8}


add\_\-handler adds a new handler to the multicaster. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em t}]is the type, from which the handler listenses \item[{\em sock}]is the socket from which the handler will get messages \item[{\em h}]is the handler. \end{description}
\end{Desc}


Definition at line 40 of file multicaster.cpp.

\begin{Code}\begin{verbatim}43 {
44         h->add_listener(boost::shared_ptr<handler::multicaster>(this, 
45                                                         core::null_deleter()));
46         boost::mutex::scoped_lock l(_monitor);
47         handler::multicaster::event_storage store;
48         store.type = t;
49         store.socket = sock;
50         store.handler = h;
51         _handler.push_back(store);
52 }
\end{verbatim}\end{Code}


\index{handler::multicaster@{handler::multicaster}!create@{create}}
\index{create@{create}!handler::multicaster@{handler::multicaster}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}boost::shared\_\-ptr$<$ \bf{handler::multicaster} $>$ handler::multicaster::create (boost::shared\_\-ptr$<$ \bf{network::message\_\-queue} $>$ {\em q}, int {\em num\_\-threads} = {\tt 5})\hspace{0.3cm}{\tt  [static]}}\label{classhandler_1_1multicaster_6323452451fb6259b0270a1a388c000e}


create creates the multicaster 

\begin{Desc}
\item[See also:]\doxyref{multicaster}{p.}{classhandler_1_1multicaster} \end{Desc}


Definition at line 94 of file multicaster.cpp.

\begin{Code}\begin{verbatim}96 {
97         boost::shared_ptr<handler::multicaster> ptr(
98                 new handler::multicaster(q, num_threads));
99         ptr->_this = ptr;
100         typedef list<boost::shared_ptr<handler:: event_worker> >::iterator it;
101         for(it i = ptr->_workers.begin(); i != ptr->_workers.end(); ++i) {
102                 (*i)->set_multicaster(ptr->_this);
103         }
104         return ptr;
105 }
\end{verbatim}\end{Code}


\index{handler::multicaster@{handler::multicaster}!dispatch@{dispatch}}
\index{dispatch@{dispatch}!handler::multicaster@{handler::multicaster}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void handler::multicaster::dispatch (boost::shared\_\-ptr$<$ \bf{network::message} $>$ {\em msg})}\label{classhandler_1_1multicaster_e3cc8eac6a1c432fee0120dd6a632457}


dispatch dispatches a received message. This method is called by worker\_\-thread threads. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em msg}]is a message from the message\_\-queue. \end{description}
\end{Desc}


Definition at line 25 of file multicaster.cpp.

\begin{Code}\begin{verbatim}26 {
27         list<handler::multicaster::event_storage> copy;
28         {
29                 boost::mutex::scoped_lock l(_monitor);
30                 copy = _handler;
31         }
32         typedef list<handler::multicaster::event_storage>::iterator it;
33         for(it i = copy.begin(); i != copy.end(); ++i) {
34                 if(i->type == msg->type && i->socket == msg->sock) {
35                         i->handler->handle_event(msg);
36                 }
37         }
38 }
\end{verbatim}\end{Code}


\index{handler::multicaster@{handler::multicaster}!notify@{notify}}
\index{notify@{notify}!handler::multicaster@{handler::multicaster}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void handler::multicaster::notify (const \bf{network::notifier} $\ast$ {\em n})\hspace{0.3cm}{\tt  [virtual]}}\label{classhandler_1_1multicaster_8796f00d3f72ca8f5b16d941afe31222}


notify is called by handler, if they want to delete themselves, if e.g. a connection was closed. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em n}]is the notifier (\doxyref{event\_\-handler}{p.}{classhandler_1_1event__handler}). \end{description}
\end{Desc}


Implements \bf{network::listener} \doxyref{p.}{classnetwork_1_1listener_d26c010ecaab2a6eb7db4c0e4b40709a}.

Definition at line 73 of file multicaster.cpp.

\begin{Code}\begin{verbatim}74 {
75         const handler::event_handler *h = 
76                 dynamic_cast<const handler::event_handler*>(n);
77         if(!h) {
78                 return;
79         }
80         boost::mutex::scoped_lock l(_monitor);
81         typedef list<handler::multicaster::event_storage>::iterator it;
82 
83         it i = _handler.begin();
84         it next = _handler.begin();
85         while(i != _handler.end()) {
86                 ++next;
87                 if(i->handler.get() == h) {
88                         _handler.erase(i);
89                 }
90                 i = next;
91         }
92 }
\end{verbatim}\end{Code}




The documentation for this class was generated from the following files:\begin{CompactItemize}
\item 
handler/multicaster.h\item 
handler/multicaster.cpp\end{CompactItemize}
